package com.hzlx.routes.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.routes.domain.ProcessRoutes;
import com.hzlx.routes.service.IProcessRoutesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺路线Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/base")
public class ProcessRoutesController extends BaseController
{
    @Autowired
    private IProcessRoutesService processRoutesService;

    /**
     * 查询工艺路线列表
     */
    @RequiresPermissions("base-data-service:routes:list")
    @GetMapping("/routes/list")
    public TableDataInfo list(ProcessRoutes processRoutes)
    {
        startPage();
        List<ProcessRoutes> list = processRoutesService.selectProcessRoutesList(processRoutes);
        return getDataTable(list);
    }

    @GetMapping("/routes/products/list")
    public TableDataInfo RPlist(ProcessRoutes processRoutes){
        startPage();
        List<ProcessRoutes> rplist = processRoutesService.selectProcessRoutesProductsList(processRoutes);
        return getDataTable(rplist);
    }

    /**
     * 导出工艺路线列表
     */
    @RequiresPermissions("base-data-service:routes:export")
    @Log(title = "工序参数", businessType = BusinessType.EXPORT)
    @PostMapping("/routes/export")
    public void export(HttpServletResponse response, ProcessRoutes processRoutes)
    {
        List<ProcessRoutes> list = processRoutesService.selectProcessRoutesList(processRoutes);
        ExcelUtil<ProcessRoutes> util = new ExcelUtil<ProcessRoutes>(ProcessRoutes.class);
        util.exportExcel(response, list, "工艺路线数据");
    }


    /**
     * 获取工艺路线详细信息
     */
    @RequiresPermissions("base-data-service:routes:query")
    @GetMapping(value = "/routes/{routeId}")
    public AjaxResult getInfo(@PathVariable("routeId") Long routeId)
    {
        return success(processRoutesService.selectProcessRoutesByRouteId(routeId));
    }

    /**
     * 新增工艺路线
     */
    @RequiresPermissions("base-data-service:routes:add")
    @Log(title = "工艺路线", businessType = BusinessType.INSERT)
    @PostMapping("/routes")
    public AjaxResult add(@RequestBody ProcessRoutes processRoutes)
    {
        return toAjax(processRoutesService.insertProcessRoutes(processRoutes));
    }

    /**
     * 修改工艺路线
     */
    @RequiresPermissions("base-data-service:routes:edit")
    @Log(title = "工艺路线", businessType = BusinessType.UPDATE)
    @PutMapping("/routes")
    public AjaxResult edit(@RequestBody ProcessRoutes processRoutes)
    {
        return toAjax(processRoutesService.updateProcessRoutes(processRoutes));
    }

    /**
     * 删除工艺路线
     */
    @RequiresPermissions("base-data-service:routes:remove")
    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/routes/{routeIds}")
    public AjaxResult remove(@PathVariable Long[] routeIds)
    {
        return toAjax(processRoutesService.deleteProcessRoutesByRouteIds(routeIds));
    }
}
